package j73;

import cn.hutool.bloomfilter.bitMap.BitMap;

import java.lang.ref.SoftReference;

/**
 * @author chengshuai
 * @date 2021/4/18 13:03
 */
public class Test2 {

    /**
     * jvm配置,故意产生大对象并配置小的内存,让它内存不够用了导致OOM,看软引用的回收情况
     * -Xms5m -Xmx5m -XX:+PrintGCDetails
     */
    public static void main(String[] args) {
        f1();
    }

    public static void f1() {
        Object o1 = new Object();
        SoftReference<Object> reference = new SoftReference<>(o1);
        System.out.println(o1);
        System.out.println(reference.get());
        o1 = null;
        try {
            byte[] bytes = new byte[30 * 1024 * 1024];
        } catch (Throwable e) {
            e.printStackTrace();
        }finally {
            System.out.println(o1);
            System.out.println(reference.get());
        }
    }
}
